<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :inline="true" :model="queryParams" label-width="68px" >
      <el-form-item label="公告标题" prop="noticeTitle">
        <el-input
          v-model="queryParams.noticeTitle"
          clearable
          placeholder="请输入公告标题"
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="类型" prop="noticeType">
        <el-select v-model="queryParams.noticeType" clearable placeholder="公告类型" size="small">
          <el-option
            v-for="dict in typeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="读取状态" prop="status">
        <el-select v-model="queryParams.status" clearable placeholder="读取状态" size="small">
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" size="small" type="primary" @click="handleQuery">搜索</el-button>

      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="noticeList" >
      <el-table-column align="center" type="selection" width="55"/>
      <el-table-column align="center" label="序号" prop="noticeId" width="100"/>
      <el-table-column
        :show-overflow-tooltip="true"
        align="center"
        label="公告标题"
        prop="noticeTitle"
      />
      <el-table-column
        :formatter="typeFormat"
        align="center"
        label="公告类型"
        prop="noticeType"
        width="100"
      />
      <el-table-column
        :formatter="statusFormat"
        align="center"
        label="状态"
        prop="status"
        width="100"
      />
      <el-table-column align="center" class-name="small-padding fixed-width" label="查看详情">
        <template slot-scope="scope">
          <el-button
            size="small"
            @click="handleUpdate(scope.row)"
          >查看详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :limit.sync="queryParams.pageSize"
      :page.sync="queryParams.pageNum"
      :total="total"
      @pagination="getList"
    />

    <!-- 添加或修改公告对话框 -->
    <el-dialog :title="title" :visible.sync="open" append-to-body width="780px">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px"  >
            <el-form-item label="公告标题" prop="noticeTitle">
              <el-input v-model="form.noticeTitle" placeholder="请输入公告标题"/>
            </el-form-item>
            <el-form-item label="附件" prop="noticeFile" style="border: 100px;" >
                <el-link :href="`${baseUrl}${form.noticeFile}`" style="margin: 10px;" :underline="false">
                  <template v-if="form.noticeFile">
                    {{form.noticeFile.toString().substring(form.noticeFile.lastIndexOf("/") + 1)}}
                  </template>
                </el-link>
            </el-form-item>
            <el-form-item label="内容">
              <el-input type="textarea" v-html="form.noticeContent" style="height: 200px;" ></el-input>
            </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer tianjie_button" style="text-align: center">
        <el-button type="primary" @click="submitForm">确 定</el-button>

      </div>
    </el-dialog>
  </div>
</template>

<script>
import {getNotice_common,listNotice_common,editNotice_common} from "@/api/system/notice";
import {InfoItem} from "@/api/enterprise/info";
export default {
  name: "test",
  data() {
    return {
      baseUrl: process.env.VUE_APP_BASE_API,
      // 遮罩层
          isActive:1,
      loading: true,
      checked:false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 公告表格数据
      noticeList: [],
      fileList:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 类型数据字典
      statusOptions: [],
      data: [],
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      // 状态数据字典
      typeOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        noticeTitle: undefined,
        createBy: undefined,
        status: undefined,
        noticeEp:undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        noticeTitle: [
          {required: true, message: "公告标题不能为空", trigger: "blur"}
        ],
        noticeType: [
          {required: true, message: "公告类型不能为空", trigger: "change"}
        ]
      }
    };
  },
  created() {

    this.getList();
    this.getDicts("sys_notice_status").then(response => {
      this.statusOptions = response.data;
    });
    this.getDicts("sys_notice_type").then(response => {
      this.typeOptions = response.data;
    });

  },
  computed:{

},
  methods: {
    ipaddrArray(value){
      console.log(value);
      //return value.toString();
    },
    read(index) {
      this.isActive = index;
    },
    look() {

    },
    /** 查询公告列表 */
    getList() {
      this.loading = true;
      const username = this.$store.state.user.name;
      InfoItem(username).then(res => {
        this.queryParams.noticeEp = res.data.epId;
        listNotice_common(this.queryParams).then(response => {
          this.noticeList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      })
    },
    // 公告状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 公告状态字典翻译
    typeFormat(row, column) {
      return this.selectDictLabel(this.typeOptions, row.noticeType);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        noticeId: undefined,
        noticeTitle: undefined,
        noticeType: undefined,
        noticeContent: undefined,
        status: "0",
        noticeFile: "",
        noticeEp: "",
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    submitForm(){
      this.form.status = 1;
      editNotice_common(this.form).then(res => {
        this.open = false;
        this.queryParams.status = 0;
        listNotice_common(this.queryParams).then(response => {
          this.queryParams.status = undefined;
          this.$addStorageEvent(1, "noticeNum", response.total) // speedInfo是后台传过来的未读消息数量
        });
        this.getList();
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const noticeId = row.noticeId || this.ids
      getNotice_common(noticeId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "公告详情";
      });
    },
  }
}
</script>

<style scoped>
.header-table-item{
   height: 40px;
  line-height: 40px;
  padding-left: 20px;
  border-bottom: 1px solid #ccc;
}
.own-space-message-content {
  position: relative;
  width: 100%;
}

.message-main-content {
  position: absolute;
  inset: 0px;
}

.message-mainlist-content {
  position: absolute;
  left: 0px;
  top: 10px;
  width: 300px;
  bottom: 0px;
  padding: 10px 0px;
}

.message-mainlist-content div {
  padding: 10px;
  margin: 0px 20px;
  border-bottom: 1px dashed rgb(210, 211, 210);
}

.message-mainlist-content div:last-child {
  border: none;
}

.message-mainlist-content div .mes-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
}

.message-mainlist-content div .message-count-badge-outer {
  margin-left: 5px;
}

.message-mainlist-content div .message-count-badge {
  background: rgb(210, 211, 210);
}

.message-mainlist-content div .message-count-badge-red {
  background: rgb(237, 63, 20);
}

.message-mainlist-content div .mes-type-btn-text {
  margin-left: 10px;
  cursor: pointer;
}
.message-mainlist-content div .mes-type-btn-text.mes-type-active{
      color: #00afff;
}
.message-content-content {
  position: absolute;
  inset: 10px 10px 10px 300px;
  background: rgb(255, 255, 255);
  border-radius: 3px;
  box-shadow: rgba(0, 0, 0, 0.1) 2px 2px 10px 2px;
  overflow: auto;
}

.message-content-content .message-title-list-content {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background-color: #fff;
}

.message-content-content .message-title-list-content .message-page {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 20px 30px 20px 25px;
}

.message-content-content .message-content-top-bar {
  height: 40px;
  width: 100%;
  background: rgb(255, 255, 255);
  position: absolute;
  left: 0px;
  top: 0px;
  border-bottom: 1px solid rgb(222, 222, 219);
}

.message-content-content .message-content-top-bar .mes-back-btn-content {
  position: absolute;
  width: 70px;
  height: 30px;
  left: 0px;
  top: 5px;
}

.message-content-content .message-content-top-bar .mes-title {
  position: absolute;
  inset: 0px 70px;
  line-height: 40px;
  padding: 0px 30px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

.message-content-content .mes-time-content {
  position: absolute;
  width: 100%;
  top: 40px;
  left: 0px;
  padding: 20px 0px;
  text-align: center;
  font-size: 14px;
  color: rgb(183, 183, 181);
}

.message-content-content .message-content-body {
  position: absolute;
  inset: 90px 0px 0px;
  overflow: auto;
}

.message-content-content .message-content-body .message-content {
  padding: 10px 20px;
}

.back-message-list-enter, .back-message-list-leave-to {
  opacity: 0;
}

.back-message-list-enter-active, .back-message-list-leave-active {
  transition: all 0.5s ease 0s;
}

.back-message-list-enter-to, .back-message-list-leave {
  opacity: 1;
}

.view-message-enter, .view-message-leave-to {
  opacity: 0;
}

.view-message-enter-active, .view-message-leave-active {
  transition: all 0.5s ease 0s;
}

.view-message-enter-to, .view-message-leave {
  opacity: 1;
}

.mes-current-type-btn-enter, .mes-current-type-btn-leave-to {
  opacity: 0;
  width: 0px;
}

.mes-current-type-btn-enter-active, .mes-current-type-btn-leave-active {
  transition: all 0.3s ease 0s;
}

.mes-current-type-btn-enter-to, .mes-current-type-btn-leave {
  opacity: 1;
  width: 12px;
}

</style>
